<?php
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/db/BaseDAO.php';
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/util/plog/classes/plog.php';

class ClickedAdSumpayDAO extends BaseDAO {
	
	public function __construct() {
		parent::__construct ();
		$this->log = Plog::factory ( __FILE__ );
	}
	public function insertData($attr){
		$sql=$this->genInserSQL('clickedadsumpay',$attr);
		$result = mysql_query ( $sql );
		return $result;
	}
	public function insertPojo($appId,$account){
		$sql = "insert into clickedadsumpay   
		  			 (APPID,Account,SumPayMoney)
		  			 values( $appId,'$account',0)";
		
		$result = mysql_query ( $sql );
		return $result;
			}
	public function addMoney($appId,$account,$payMoney){
		
		$sql = "update clickedadsumpay set  
		  			 SumPayMoney=SumPayMoney+$payMoney
		  			 where appid= $appId and account = '$account'";
//		/echo "<br/>".$sql;
		$result = mysql_query ( $sql );
		return $result;
	}

	public function cnt($appid, $account) {
		$sql = "select count(*) count from clickedadsumpay  where  appid = $appid and account = '$account'";
		$result = @mysql_query($sql);
		$row = @mysql_fetch_assoc($result);
		return $row['count'];
	}
	
	public function getSumPayByAccount($account){
		$sql="SELECT SUM(SumPayMoney) Sum FROM clickedadsumpay WHERE ACCOUNT='$account'";
		$result = mysql_query ( $sql );
		$row=mysql_fetch_assoc($result);
		$sum=$row["Sum"];
		@mysql_free_result($result);
		if(!isset($sum)){
			$sum=0;
		}
		return $sum;
	}
}
?>